package com.es.spring.aop.chain;

import com.es.spring.aop.common.Person;
import com.es.spring.aop.common.TargetMethod;
import com.es.spring.aop.common.ZhangSan;

/**
 * @author 二十
 * @since 2021/11/9 9:57 下午
 */
public class ChainMain {

    public static void main(String[] args) {
        AbstractSlot head = new AbstractSlot.Head();
        AbstractSlot one = new One();
        AbstractSlot two = new Two();

        head.setNext(one);
        one.setNext(two);

        ((Person) new JdkDynamic(new ZhangSan(), head).getProxy()).eat("可比克");
    }


    private static class One extends AbstractSlot {

        @Override
        Object invoke(TargetMethod targetMethod) {
            Object result = null;
            System.out.println("1");
            try {
                result = proceed(targetMethod);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("4");
            return result;
        }
    }


    private static class Two extends AbstractSlot {

        @Override
        Object invoke(TargetMethod targetMethod) {
            Object result = null;
            System.out.println("2");
            try {
                result = proceed(targetMethod);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("3");
            return result;
        }
    }
}
